home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue67 / appbars / ClipMain.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-12-19  |  4.1 KB  |  150 lines

  1. unit ClipMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ShellAPI, StdCtrls, ClipBrd;
  8.  
  9. const
  10.   wm_AppBarMessage = wm_User;
  11.  
  12. type
  13.   TClipDialog = class(TForm)
  14.     Memo1: TMemo;
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.     procedure FormShow(Sender: TObject);
  18.     procedure FormActivate(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.     abd: TAppBarData;
  22.     CBHandle: THandle;
  23.     function GetRequestRect: TRect;
  24.     procedure WMAppBarMessage(var Msg: TMessage); message wm_AppBarMessage;
  25.     procedure WMWindowPosChanged(var Msg: TWMWindowPosMsg); message WM_WindowPosChanged;
  26.     procedure WMMoving(var Msg: TMessage); message WM_Moving;
  27.     procedure WMSizing(var Msg: TMessage); message WM_Sizing;
  28.     procedure WMExitSizeMove(var Msg: TMessage); message WM_ExitSizeMove;
  29.     procedure WMChangecbchain(var Msg: TWMChangecbchain); message WM_Changecbchain;
  30.     procedure WMDrawClipboard(var Msg: TWMDrawClipboard); message WM_DrawClipboard;
  31.     property RequestRect: TRect read GetRequestRect;
  32.   public
  33.     { Public declarations }
  34.   end;
  35.  
  36. var
  37.   ClipDialog: TClipDialog;
  38.  
  39. implementation
  40.  
  41. {$R *.DFM}
  42.  
  43. procedure TClipDialog.FormCreate(Sender: TObject);
  44. begin
  45.   // fill the AppBarData data structure
  46.   abd.cbSize := sizeof(abd);
  47.   abd.hWnd := Handle;
  48.   abd.uCallBackMessage := wm_AppBarMessage;
  49.   abd.uEdge := ABE_BOTTOM;
  50.   abd.rc := RequestRect;
  51.   abd.lParam := 0;
  52.   SHAppBarMessage(ABM_NEW, abd);
  53.  
  54.   // set the initial size and position
  55.   SHAppBarMessage(ABM_QUERYPOS, abd);
  56.   abd.rc.Top := abd.rc.Bottom - Height;
  57.   SHAppBarMessage(ABM_SETPOS, abd);
  58.   SetBounds(abd.rc.Left, abd.rc.Bottom - Height, abd.rc.Right-abd.rc.Left, Height);
  59.  
  60.   // set as clipboard viewer
  61.   CBHandle := SetClipboardViewer(Handle);
  62. end;
  63.  
  64. procedure TClipDialog.FormDestroy(Sender: TObject);
  65. begin
  66.   SHAppBarMessage(ABM_REMOVE, abd);
  67.   ChangeClipboardChain(Handle, CBHandle);
  68. end;
  69.  
  70. procedure TClipDialog.FormShow(Sender: TObject);
  71. begin
  72.   ShowWindow(Application.Handle, SW_HIDE);
  73. end;
  74.  
  75. procedure TClipDialog.FormActivate(Sender: TObject);
  76. begin
  77.   SHAppBarMessage(ABM_ACTIVATE, abd);
  78. end;
  79.  
  80. function TClipDialog.GetRequestRect: TRect;
  81. begin
  82.   // set the requested Rect
  83.   Result.Left := 0;
  84.   Result.Top := Screen.Height - Height;
  85.   Result.Right := Screen.Width;
  86.   Result.Bottom := Screen.Height;
  87. end;
  88.  
  89. procedure TClipDialog.WMAppBarMessage(var Msg: TMessage);
  90. begin
  91.   // hide when fullscreen apps are displayed
  92.   if Msg.wParam = ABN_FULLSCREENAPP then
  93.     if Msg.lParam <> 0 then Hide else Show;
  94.  
  95.   if Msg.wParam = ABN_POSCHANGED then
  96.   begin
  97.     // fill the AppBarData data structure
  98.     abd.rc := RequestRect;
  99.     SHAppBarMessage(ABM_QUERYPOS, abd);
  100.     abd.rc.Top := abd.rc.Bottom - Height;
  101.     SHAppBarMessage(ABM_SETPOS, abd);
  102.     SetBounds(abd.rc.Left, abd.rc.Bottom - Height, abd.rc.Right-abd.rc.Left, Height);
  103.   end;
  104. end;
  105.  
  106. procedure TClipDialog.WMWindowPosChanged(var Msg: TWMWindowPosMsg);
  107. begin
  108.   // must send this message to maintain correct Z-order
  109.   SHAppBarMessage(ABM_WINDOWPOSCHANGED, abd);
  110.   inherited;
  111. end;
  112.  
  113. procedure TClipDialog.WMMoving(var Msg: TMessage);
  114. begin
  115.   PRect(Msg.lParam)^ := abd.rc;
  116.   inherited;
  117. end;
  118.  
  119. procedure TClipDialog.WMSizing(var Msg: TMessage);
  120. begin
  121.   PRect(Msg.lParam)^ := Rect(Left, PRect(Msg.lParam)^.Top, Width, PRect(Msg.lParam)^.Bottom);
  122.   inherited;
  123. end;
  124.  
  125. procedure TClipDialog.WMExitSizeMove(var Msg: TMessage);
  126. begin
  127.   abd.rc.Top := abd.rc.Bottom - Height;
  128.   SetBounds(abd.rc.Left, abd.rc.Top, abd.rc.Right-abd.rc.Left, abd.rc.Bottom-abd.rc.Top);
  129.   SHAppBarMessage(ABM_SETPOS, abd);
  130.   inherited;
  131. end;
  132.  
  133. procedure TClipDialog.WMDrawClipboard(var Msg: TWMDrawClipboard);
  134. begin
  135.   Memo1.Text := Clipboard.AsText;
  136.   SendMessage(CBHandle, WM_DrawClipboard, 0, 0);
  137.   inherited;
  138. end;
  139.  
  140. procedure TClipDialog.WMChangecbchain(var Msg: TWMChangecbchain);
  141. begin
  142.   if Msg.Remove <> CBHandle then
  143.     SendMessage(Msg.Next, WM_Changecbchain, Msg.Remove, Msg.Next)
  144.   else
  145.     CBHandle := Msg.Next;
  146.   inherited;
  147. end;
  148.  
  149. end.
  150.